package com.mvc.UtilS;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @auther linke
 * @create 2021-10-21 17:59
 * 工具类 获取Session对象
 */
public class SessionUtil {

    public static SqlSession getSqlSession() throws Exception {

        InputStream is = Resources.getResourceAsStream("mybatis_config.xml");

        SqlSessionFactoryBuilder build = new SqlSessionFactoryBuilder();

        SqlSessionFactory factory = build.build(is);

        return factory.openSession();
    }


}
